<?php
/**
 * Description of db
 * This file contains main functions used to interact with DB
 *
 * @author Andrei.Carpatiuc
 */
session_start();
require_once '../../config.inc';
require_once '../../lib/common.inc.php';
if (isset ($_SESSION["token"])){  
  $mysql=new mySQL(array( "db_user" => $_SESSION["dbuser"],
                          "db_pass" => $_SESSION["dbpass"],
                          "db_host" => DB_HOST));
  if (!$mysql->dbconnect()){
    echo encodeResponse(false,"Can't connect to mySQL Server. Username or password incorect");
    exit();
  }else{
    $mysql->selected_db($_SESSION["selDB"]);    
    
  }

}
else {echo "error";exit();}



if (isset($_REQUEST["act"])){

  $action=$_REQUEST["act"];
  switch ($action){
    case "getDBs":
        $db=$mysql->getDatabases();
       echo json_encode(array('dbs'=>$db));
      break;
    case "getObjects":
      echo json_encode(array(array("text"=>"tables","iconCls"=>"dbtable-ico"),array("text"=>"views","iconCls"=>"dbview-ico"),array("text"=>"procedures","iconCls"=>"procedure-ico"),array("text"=>"functions","iconCls"=>"function-ico"),"triggers",));
      break;
  }
}


?>
